<%@ page language="java" import="java.util.*"
	import="com.gxuwz.medical.domain.user.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="../../css/styles.css">
<link rel="stylesheet" href="../../css/admin.css">
<link href="../../third/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="../../third/zTree_v3/js/jquery-1.4.4.min.js"></script>
<script src="../../js/admin.js"></script>
<script type="text/javascript" src="../../third/zTree_v3/js/jquery.ztree.all.min.js"></script>
<script type="text/javascript">
	$(function() {
		var ret;
		$.ajax({
			cache : true,
			type : "post",
			url : "tree.right",
			data : "{}",
			async : false,
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert(XMLHttpRequest.status);
				alert(XMLHttpRequest.readyState);
				alert(textStatus);
			},
			success : function(data) {
				console.log(data);
				ret = JSON.parse(data);
				console.log(ret.name);
			
			}
		});

				var setting = {
					check : {
						enable : true,
						chkStyle : "checkbox",//显示 checkbox 选择框，默认checkbox可选择值radio
						chkboxType: { "Y": "ps", "N": "ps" }
					},
					data: {
					   simpleData: {
					   enable: false, //设置是否启用简单数据格式（zTree支持标准数据格式跟简单数据格式，上面例子中是标准数据格式）
					   idKey: "id", //设置启用简单数据格式时id对应的属性名称
					   pidKey: "pid" //设置启用简单数据格式时parentId对应的属性名称,ztree根据id及pid层级关系构建树结构
					  	}
					  }
				};
				var city = $.fn.zTree.init($("#ztree"), setting, ret);	
		//第一个参数为zTree的DOM容器，第二个为zTree设置详情可见官网api,第三个为zTree的节点数据 
	});
	function send(){
	
		var treeobj = $.fn.zTree.getZTreeObj("ztree");
    	var node_checked = treeobj.getCheckedNodes(true);
    	var list = new Array();
    	for(var i=0;i<node_checked.length;i++){
    		list.push(node_checked[i].id);
    	}
    	var id =JSON.stringify(list)
    	console.log("selected node:"+id);	
    	document.getElementById("addrole").action="add.role?id="+id;
    	document.getElementById("addrole").submit();
	}
</script>
</head>
<body>
	<div class="panel admin-panel">
		<div class="panel-head" id="add">
			<strong><span class="icon-pencil-square-o"></span>添加角色</strong>
		</div>
		<div class="body-content">
			<form method="post" class="form-x" action="add.role" id="addrole">
				<div class="form-group">
					<div class="label">
						<label>角色编码：</label>
					</div>
					<div class="field">
						<input type="text" class="input w50" value="" name="roleid"
							data-validate="required:请输入角色编码" />
					</div>
				</div>

				<div class="form-group">
					<div class="label">
						<label>角色名称：</label>
					</div>
					<div class="field">
						<input type="text" class="input w50" value="" name="roleName"
							data-validate="required:请输入角色名称" />
					</div>
				</div>

				<div class="form-group">
					<div class="label">
						<label>权限：</label>
					</div>
					<div class="field">
						<ul id="ztree" class="ztree" style="width:230px; overflow:auto;"></ul>
					</div>
				</div>	

				<div class="form-group">
					<div class="label">
						<label></label>
					</div>
					<div class="field">
						<a class="button bg-main icon-check-square-o" onclick="send()">
							提交</a>
					</div>
				</div>

			</form>
		</div>
	</div>

</body>
</html>